const api = require("../../utils/cloudAPIUtils");
const app = getApp();

Page({
  data: {
      formData:{
        name:'',
        phone:'',
        province:'',
        city:'',
        cityArea:'',
        note:''
      }
  },

  btnInput(e){
      const formData = this.data.formData;
      formData[e.currentTarget.dataset.key] = e.detail.value;
      this.setData({formData})
  },

  btnPicker(e){
      const data = e.detail.value;
      const formData = this.data.formData;
      formData.province=data[0];
      formData.city=data[1];
      formData.cityArea=data[2];
      this.setData({formData})
  },

  btnSubmit(){
    const formData = this.data.formData;
    console.log(formData)
    if(!formData.name||!formData.phone||!formData.province){
        wx.showModal({
          title: '温馨提示',
          content: '请填写姓名/电话/地区',
          showCancel:false
        })
        return
    }
    if(!formData.note){
        wx.showModal({
          title: '温馨提示',
          content: '请填写留言',
          showCancel:false
        })
        return
    }
    api.post(api.url.commonPlaceRecommend,formData,res=>{
        console.log(res)
        if(res.data.code == 200){
            wx.showToast({
              title: '提交成功！',
              icon:'success',
              mask:false,
              success(){
                  setTimeout(()=>{
                      wx.navigateBack();
                  },1000)
              }
            })
        }else{
            wx.showToast({
                title: res.data.msg,
                icon:'error',
                mask:false,
            })
        }
    })
  },

  onLoad(options) {

  }
})